<?php
namespace app\index\model;
use think\Model;
use think\model\Merge;

/**
 * Created by PhpStorm.
 * User: jieai
 * Date: 2017-07-27
 * Time: 11:30
 */
class Level extends Model {


    public function member()
    {
        return $this->belongsTo('member');
}
    
    protected $type=[
        'starttime'=>'timestamp:Y-m-d  H:i',
        'stoptime'=>'timestamp:Y-m-d  H:i'
    ];
    protected $auto   = ['duration'];


    protected  $autoWriteTimestamp=true;
    protected $updateTime=false;
    protected $createTime='createtime';

    public function setDurationAttr($value,$data)
    {
        $dur= ($data['stoptime']-$data['starttime'])/60/30;//单位为半小时
        if ($data['leixing']==0){
            return $dur>=16?16:$dur;
        }else{
            return $dur;
        }

    }

    public function getMembernameAttr($value,$data)
    {
        return Member::get($data['member_id'])->name;
    }

    public function getLeixingAttr($value)
    {
        $status=[0=>'请假',1=>'加班'];
        return $status[$value];
    }

    public function getDurationAttr($value)
    {
        $hour=$value/2;
        return $hour."小时";

    }
    public function getPendAttr($value)
    {
        $status=[0=>'未审核',1=>'已审核'];
        return $status[$value];
    }

}